package com.ruoyi.project.digital.util;

import javafx.embed.swing.SwingFXUtils;
import lombok.Data;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.imageio.ImageIO;

@Data
public class Choices {

    private Integer index;
    private List<Message> message;
    private String finish_reason;

    public static void main(String[] args) throws IOException {


        try {
            // 读取图片
            BufferedImage image = ImageIO.read(new File("D://d9ec49897480496d9a4c32064561e1ea.jpg"));

            // 创建一个新的BufferedImage，设置宽度、高度和类型
            BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);

            // 获取新图像的Graphics2D对象
            Graphics2D graphics = newImage.createGraphics();

            // 将背景设置为白色
            graphics.setColor(Color.WHITE);
            graphics.fillRect(0, 0, newImage.getWidth(), newImage.getHeight());

            // 将原始图像绘制到新图像中
            graphics.drawImage(image, 0, 0, null);
            graphics.dispose();

            // 将新图像保存到文件
            ImageIO.write(newImage, "jpg", new File("D://output.jpg"));

            System.out.println("图片背景已转为白色并保存成功！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
